//--------------------------------------------------------------------------------
// This file is a portion of the D2D1Renderer.  It is distributed
// under the MIT License, available in the root of this distribution and 
// at the following URL:
//
// http://www.opensource.org/licenses/mit-license.php
//
// Copyright (c) Mirco Timmermann
//
//--------------------------------------------------------------------------------
#pragma once

#include "..\DisplayObject.h"


namespace D2 {

class ScrollBar : public DisplayObject {
	friend class ScrollBarContainer;

public:
	enum ScrollBarType {
		VERTICAL, 
		HORIZONTAL
	};

public:
	ScrollBar(int x, int y, int width, int height, ScrollBarType type);
	virtual ~ScrollBar(void);

	virtual bool Draw(Direct2DContext* ctx, D2D1::Matrix3x2F* mtx = 0);

private:
	void Draw_background(Direct2DContext* ctx);

	void DrawBar_horizontal(Direct2DContext* ctx);
	void DrawBar_vertical(Direct2DContext* ctx);

private:
	bool HitTestBar(int x, int y);
	int GetBarOffsetByDistance(float x);
	int ClampTimeDistance(int i);

public:
/////////////
	virtual void OnMouseDown0(const MouseEvent &e);

	virtual void OnMouseUp0(const MouseEvent &e);
	virtual void OnMouseLeave0(const MouseEvent &e);
	virtual void OnMouseRaise0(const MouseEvent &e);

	virtual void OnMouseDrag0(const MouseEvent &e);

	//virtual void OnMouseRaise0(const MouseEvent &e);
	//virtual void OnMouseLeave0(const MouseEvent &e);

private:
	ScrollBarType _type;

	int _minValue;
	int _maxValue;

	int _leftValue;
	int _rightValue;

	//
	float _step;
	
//visualisation temp members.
	int _bar_x;
	int _bar_y;
	int _bar_width;
	int _bar_height;
//

	float _left_offset;
	float _right_offset;

	bool _barPressed;
	float _tempMouseDistance;

public:
	void Refresh();
	void CalculateStep();

	void CalculateBarRectangle();

public:
	void SetMinValue(int value);
	void SetMaxValue(int value);

	void SetLeftValue(int value);
	void SetRightValue(int value);

	void SetBarByHeight(int totalHeight, int height = -1);
	void SetBarByRatio(float ratio);
};

}